public class PrimaryExpression extends MultExpression
{
	DataInfo dataInfo;

	String type = "";
	String value = "";
	String nmType = "";
	CallExpr callExpr = null;
	Expression expr = null;

	public PrimaryExpression( String type, String value, CallExpr callExpr, Expression expr, DataInfo dataInfo )
	{
		this.type = type;
		this.value = value;
		this.callExpr = callExpr;
		this.expr = expr;

		this.dataInfo = dataInfo;

		if( type != null )
		{
			if( type.equals( "NM" ) )
			{
				if( value.contains( "." ) )
				{
					nmType = "float";
				}
				else
				{
					nmType = "int";
				}
			}
		}
	}

	public String toString()
	{
		if( type != null )
		{
			return value + "\n";
		}
		if( callExpr != null )
		{
			return callExpr.toString();
		}
		if( expr != null )
		{
			return expr.toString();
		}
		return "Error";
	}

	public String getType() throws SemanticException
	{

		SymbolTable st = SymbolTable.getInstance();

		if( type != null )
		{

			if( type.equalsIgnoreCase( "NM" ) )
				return (nmType);

			if( type.equalsIgnoreCase( "ID" ) )
				if( !st.contains( value ) )
				{
					String details = "The identifier " + value + " has not been declared.";
					if( dataInfo != null )
						throw new SemanticException( dataInfo.lineNumber, dataInfo.charNumber, dataInfo.line, details );
					else
						throw new SemanticException( details );
					
				}
				else
					return (st.get( value ).type);

			if( type.equalsIgnoreCase( "BL" ) )
				return ("boolean");

			return ("String");

		}

		if( callExpr != null )
			return (callExpr.getType());

		if( expr != null )
			return (expr.getType());

		return ("");

	}

	public void check() throws SemanticException
	{

		if( callExpr != null )
			callExpr.check();

		if( expr != null )
			expr.check();

	}

}